var CxsStatsContrls = angular.module('CxsStatsContrls', []);//申明自定义模块

CxsStatsContrls.controller('CxsStatsCtrl', ['$scope','$routeParams', function ($scope,$routeParams) {
    $scope.CxsName=$routeParams.CxsName;

    //获取数据源
    $scope.GetDataSource=function(){
        $.ajax({
            type: 'Get',
            url: './Data/cxsStats.json',
            data: {CxsName:$scope.CxsName},
            dataType: 'json',
            contentType: "application/json",
            success: function (data) {
                $scope.$apply(function () {
                    $scope.QX=data.QX;
                    $scope.ZTPJ=data.ZTPJ;
                    $scope.QYLX=data.QYLX;
                    $scope.DataSoures=data.DataSoures;

                    $scope.initChart();
                });
            }
        });
    }
    $scope.GetDataSource();

    //echart初始化
    $scope.initChart=function () {
        var myChart1 = echarts.init(document.getElementById('cxsStatsChart1'));
        var myChart2 = echarts.init(document.getElementById('cxsStatsChart2'));
        var myChart3 = echarts.init(document.getElementById('cxsStatsChart3'));

        var option1 = {
            title : {
                text: '期限维度',
                //subtext: '纯属虚构',
                x:'center'
            },
            tooltip : {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            legend: {
                x : 'center',
                y : 'bottom',
                data:['≤6M','6M-1Y','1Y-3Y','3Y-5Y','＞5Y']
            },
            toolbox: {
                show : true,
                feature : {
                    mark : {show: true},
                    dataView : {show: true, readOnly: false},
                    magicType : {
                        show: true,
                        type: ['pie', 'funnel']
                    },
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            series : [
                {
                    name:'期限维度',
                    type:'pie',
                    radius : [0, 80],
                    center : ['50%', '50%'],
                    roseType : 'area',
                    data:$scope.QX
                }
            ]
        };

        var option2 = {
            title : {
                text: '主体评级维度',
                //subtext: '纯属虚构',
                x:'center'
            },
            tooltip : {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            legend: {
                x : 'center',
                y : 'bottom',
                data:['AA-','AA','AA+','AAA-','AAA','其他']
            },
            toolbox: {
                show : true,
                feature : {
                    mark : {show: true},
                    dataView : {show: true, readOnly: false},
                    magicType : {
                        show: true,
                        type: ['pie', 'funnel']
                    },
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            series : [
                {
                    name:'主体评级维度',
                    type:'pie',
                    radius : [0, 80],
                    center : ['50%', '50%'],
                    roseType : 'area',
                    data:$scope.ZTPJ
                }
            ]
        };

        var option3 = {
            title : {
                text: '企业类型维度',
                //subtext: '纯属虚构',
                x:'center'
            },
            tooltip : {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            legend: {
                x : 'center',
                y : 'bottom',
                data:['央企及子公司','地方国企','集体企业','民营企业','其他']
            },
            toolbox: {
                show : true,
                feature : {
                    mark : {show: true},
                    dataView : {show: true, readOnly: false},
                    magicType : {
                        show: true,
                        type: ['pie', 'funnel']
                    },
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            series : [
                {
                    name:'企业类型维度',
                    type:'pie',
                    radius : [0, 80],
                    center : ['50%', '50%'],
                    roseType : 'area',
                    data:$scope.QYLX
                }
            ]
        };

        myChart1.setOption(option1);
        //容器自适应
        window.onresize = myChart1.resize;

        myChart2.setOption(option2);
        //容器自适应
        window.onresize = myChart2.resize;

        myChart3.setOption(option3);
        //容器自适应
        window.onresize = myChart3.resize;
    }
}]);
